function refresh() {
    tableIn.reload('btable');
}

$(function () {
    $.ajax({
        type:'get',
        url:'/personal/count',
        success:function (res){
            $('#count1').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/personal/countpeople',
        success:function (res){
            $('#count2').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/personal/counttoday',
        success:function (res){
            $('#count3').val(res.state);
        }
    })

    $.ajax({
        type:'get',
        url:'/personal/counttodaypeople',
        success:function (res){
            $('#count4').val(res.state);
        }
    })
})

$(function () {
    number('/personal/count','#qb')
})

$(function () {
    number('/personal/countadopt','#ytg')
})

$(function () {
    number('/personal/countintercept','#ylj')
})

$(function () {
    number('/personal/countdelete','#ysc')
})

function number(a,b){
    $(function () {
        $.ajax({
            type:'get',
            url:a,
            success:function (res){
                $(b).text(res.state);
            }
        })
    })
}

var tableIn = null;
layui.use(['table','form'], function () {
    var table = layui.table;
    var form = layui.form;

    tableIn = table.render({
        elem: '#commenttable',
        url: '/personal/get',
        toolbar: true,
        id: 'btable',
        page: {
            limit: 10,
            limits: [5, 10, 15],
            group: 10
        },
        cols: [
            [
                {field: "id",title: "序号"},
                {field: "userAccount", title: '成员账号'},
                {field: "userNickname", title: '昵称'},
                {field: "commentDate", title: '发言时间'},
                {field: "content", title: '发言内容'},
                {field: "status", title: '状态',templet:function (obj){
                        if (obj.status == 1){
                            return "已通过";
                        }if (obj.status == 2){
                            return "已拦截";
                        }if (obj.status == 3){
                            return "已删除";
                        }
                    }},
                {toolbar: '#bardemo', title: "操作"}
            ]
        ],
        parseData: function (res) {
            return {
                "code": res.state,
                "msg": res.Message,
                "count": res.total,
                "data": res.data
            };
        },
    })


    table.on("tool(equip)", function (obj) {
        var event = obj.event;

        if (event === 'lj') {

            $.ajax({
                type:'get',
                url: "/personal/intercep",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                    console.log(obj.data);
                }
            })
        }else if (event === 'tg'){

            $.ajax({
                type:'get',
                url: "/personal/adopt",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                }
            })
        }else if (event === 'sc'){
            $.ajax({
                type:'get',
                url: "/personal/delete",
                data: {"id":obj.data.id},
                success:function (){
                    refresh();
                }
            })
        }
    })
});

$(document).on("click","button",function(){
    $("#button1").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button2").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button3").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button4").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button5").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

$(document).on("click","button",function(){
    $("#button6").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});
$(document).on("click","button",function(){
    $("#button7").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});
$(document).on("click","button",function(){
    $("#button8").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});
$(document).on("click","button",function(){
    $("#button9").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});

function qb(){
    render('/personal/count','/personal/get','/personal/countpeople','/personal/counttoday','/personal/counttodaypeople');
}

function ytg(){
    render('/personal/countadopt','/personal/getadopt','/personal/countpeopleadopt','/personal/counttodayadopt','/personal/counttodaypeopleadopt');
}

function ylj(){
    render('/personal/countintercept','/personal/getintercept','/personal/countpeopleintercept','/personal/counttodayintercept','/personal/counttodaypeopleintercept');
}

function ysc(){
    render('/personal/countdelete','/personal/getdelete','/personal/countpeopledelete','/personal/counttodaydelete','/personal/counttodaypeopledelete');
}

function qdyh(){
    render('/personal/countreceptione','/personal/reception','/personal/countpeoplereceptione','/personal/counttodayreceptione','/personal/counttodaypeoplereceptione');
}

function glry(){
    render('/personal/countbackstage','/personal/backstage','/personal/countpeoplebackstage','/personal/counttodaybackstage','/personal/counttodaypeoplebackstage');
}

function sp(){
    render('/personal/countcurriculum','/personal/curriculum','/personal/countpeoplecurriculum','/personal/counttodaycurriculum','/personal/counttodaypeoplecurriculum');
}

function kc(){
    render('/personal/countcommodity','/personal/commodity','/personal/countpeoplecommodity','/personal/counttodaycommodity','/personal/counttodaypeoplecommodity');
}

function wq(){
    render('/personal/countmicrocircle','/personal/microcircle','/personal/countpeoplemicrocircle','/personal/counttodaymicrocircle','/personal/counttodaypeoplemicrocircle');
}


function render(a,b,c,d,e){
    $(function () {
        $.ajax({
            type:'get',
            url: a,
            success:function (res){
                $('#count1').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: c,
            success:function (res){
                $('#count2').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: d,
            date:{"date":datetime},
            success:function (res){
                $('#count3').val(res.state);
            }
        })

        $.ajax({
            type:'get',
            url: e,
            date:{"date":datetime},
            success:function (res){
                $('#count4').val(res.state);
            }
        })
    })

    layui.use(['table','form'], function () {
        var table = layui.table;
        var form = layui.form;

        tableIn = table.render({
            elem: '#commenttable',
            url: b,
            toolbar: true,
            id: 'btable',
            page: {
                limit: 10,
                limits: [5, 10, 15],
                group: 10
            },
            cols: [
                [
                    {field: "id",title: "序号"},
                    {field: "userAccount", title: '成员账号'},
                    {field: "userNickname", title: '昵称'},
                    {field: "commentDate", title: '发言时间'},
                    {field: "content", title: '发言内容'},
                    {field: "status", title: '状态',templet:function (obj){
                            if (obj.status == 1){
                                return "已通过";
                            }if (obj.status == 2){
                                return "已拦截";
                            }if (obj.status == 3){
                                return "已删除";
                            }
                        }},
                    {toolbar: '#bardemo', title: "操作"}
                ]
            ],
            parseData: function (res) {
                return {
                    "code": res.state,
                    "msg": res.Message,
                    "count": res.total,
                    "data": res.data
                };
            },
        })


        table.on("tool(equip)", function (obj) {
            var event = obj.event;

            if (event === 'lj') {

                $.ajax({
                    type:'get',
                    url: "/personal/intercep",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                        console.log(obj.data);
                    }
                })
            }else if (event === 'tg'){

                $.ajax({
                    type:'get',
                    url: "/personal/adopt",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                    }
                })
            }else if (event === 'sc'){
                $.ajax({
                    type:'get',
                    url: "/personal/delete",
                    data: {"id":obj.data.id},
                    success:function (){
                        refresh();
                    }
                })
            }
        })
    });
}

